import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;

/**
 * author: MaHX
 * date: 2019/10/25/19:25
 * description:
 **/
public class TestDeadLock {
    public final Object left = new Object();
    public final Object right = new Object();
    public void leftRight() throws InterruptedException {
        synchronized (left){
            Thread.sleep(2000);
            synchronized (right){
                System.out.println("leftRight执行完成");
            }
        }
    }

    public void rightLeft() throws InterruptedException {
        synchronized (right){
            Thread.sleep(200);
            synchronized (left){
                System.out.println("rightLeft执行完成");
            }
        }
    }



    public static void main(String[] args) {
        TestDeadLock deadLock = new TestDeadLock();
        ConcurrentHashMap<String,String> concurrentHashMap = new ConcurrentHashMap<>();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    deadLock.leftRight();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"线程一").start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    deadLock.rightLeft();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"线程二").start();
    }

}
